import time
from webutils.layers.services import ManagerProxy

from .. import managers
from .base import BaseService


class Counter(BaseService):
    required_context = ['room_id', 'counter_id']
    counter = ManagerProxy(managers.Counter)

    async def add(self, uid):
        timestamp = int(time.time())
        data = {'u': uid, 't': timestamp}
        total = await self.counter.append(data)
        return total

    async def count(self):
        return await self.counter.count()
